package com.install.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.PreparedStatement;

public class BaseJdbcDao {
	private static final String DRIVER_CLASS = 
		"com.mysql.jdbc.Driver";
	private static final String DATABASE_URL =
		"jdbc:mysql://localhost:3306/install";
	private static final String DATABASE_USER = "root";
	private static final String DATABASE_PASSWORD = "sa";
	
	protected static Connection connection;
	protected static Statement statement;
	protected static PreparedStatement pStatement;
	protected static ResultSet resultSet;
	
	protected static void openConnection()
	{
		try {
			Class.forName(DRIVER_CLASS);
			connection = DriverManager.getConnection(DATABASE_URL, 
					DATABASE_USER, DATABASE_PASSWORD);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	protected static void closeAll()
	{
		if(resultSet != null)
		{
			try {
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(statement != null)
		{
			try {
				statement.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(pStatement != null)
		{
			try {
				pStatement.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(connection != null)
		{
			try {
				connection.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	public static void main(String[] args) {
		openConnection();
		System.out.println(connection);
	}
}
